package com.loop.unclelend.ui.presenter

import com.loop.unclelend.R
import com.loop.unclelend.network.ApiService
import com.loop.unclelend.network.IHttpCallback
import com.loop.unclelend.pro.ProPresenter
import com.loop.unclelend.ui.view.IView_Feedback
import org.json.JSONObject

/**
 * UncleLend
 * @Author wwdeng
 * @CreateTime: 2024/9/28 16:26
 * @Annotation：意见反馈 Presenter 实现
 */
class Pre_Feedback(private val iView: IView_Feedback): ProPresenter(iView) {

    private val typeTitleList = arrayListOf(R.string.feedback_type_suggest,R.string.feedback_type_bug,R.string.feedback_type_repayment_issues,R.string.feedback_type_other)
    private val typeValueList = arrayListOf("SUGGEST","BUG","PAYMENT","OTHER")

    //反馈类型列表
    private var typeList: ArrayList<JSONObject>? = null

    /**
     * 获取意见反馈类型
     */
    fun loadQuestionTypeListAction() {
        if (typeList == null){
            typeList = arrayListOf()
        }
        typeList!!.clear()
        for (i in 0..<typeTitleList.size){
            val obj = JSONObject()
            obj.put("title", typeTitleList[i])
            obj.put("value", typeValueList[i])
            obj.put("isSelect",false)
            typeList!!.add(obj)
        }
        iView.setUncleQuestionTypeList(typeList!!)
    }

    /**
     * 提交反馈
     */
    fun submitUncleFeedbackAction(params: JSONObject){
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.UNCLE_API_COMMON_URL)
        doPostAction(httpUrl,params,object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                val msg = data.optString("msg")
                iView.showUncleToast(msg)
                iView.showUncleSubmitSuccess()
            }

            override fun onRequestError(error: JSONObject) {
            }

            override fun onRequestFinish() {
                iView.hideUncleLoading()
            }
        })
    }

    /**
     * 获取全部问题类型列表
     */
    fun getTypeList(): ArrayList<JSONObject>{
        return typeList!!
    }
}